import api from './index'
import {axios} from '@/utils/request'

/**
 * login func
 * parameter: {
 *     username: '',
 *     password: '',
 *     remember_me: true,
 *     captcha: '12345'
 * }
 * @param parameter
 * @returns {*}
 */
export function login(parameter) {
  return axios({
    url: api.Login,
    method: 'post',
    data: parameter
  })
}

export function phoneLogin(parameter) {
  return axios({
    url: '/api/erpmng/sys/phoneLogin',
    method: 'post',
    data: parameter
  })
}

export function getSmsCaptcha(parameter) {
  return axios({
    url: api.SendSms,
    method: 'post',
    data: parameter
  })
}

// export function getInfo() {
//   return axios({
//     url: '/api/user/info',
//     method: 'get',
//     headers: {
//       'Content-Type': 'application/json;charset=UTF-8'
//     }
//   })
// }

export function getUserInfo(params) {
  return axios({
    url: '/api/erpmng/sys/oauth/userInfo',
    method: 'get',
    params
  })
}

export function logout(logoutToken) {
  return axios({
    url: api.Logout,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
      'Authorization': logoutToken
    }
  })
}

// 新的获取验证码
export function getRandomImage(parameter) {
  return axios({
    url: `${api.randomImage}/${parameter}`,
    method: 'get',
  })
}

/**
 * 第三方登录
 * @param token
 * @param thirdType
 * @returns {*}
 */
export function thirdLogin(token,thirdType) {
  return axios({
    url: `/api/erpmng/sys/thirdLogin/getLoginUser/${token}/${thirdType}`,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}



/**
 * 强退其他账号
 * @param token
 * @returns {*}
 */
 export function forceLogout(parameter) {
  return axios({
    url: '/api/erpmng/sys/online/forceLogout',
    method: 'post',
    data: parameter
  })
}



/**
 * 强退全部账号
 * @param token
 * @returns {*}
 */
 export function forceAllLogout() {
  return axios({
    url: '/api/erpmng/sys/online/forceAllLogout',
    method: 'post',
  })
}



/**
 * 强退用户账号
 * @param token
 * @returns {*}
 */
 export function forceUserLogout(parameter) {
  return axios({
    url: '/api/erpmng/sys/online/forceUserLogout',
    method: 'post',
    data: parameter
  })
}